package com.chen.web_chat.controller;

import com.chen.web_chat.entity.dto.LoginDto;
import com.chen.web_chat.entity.enumerate.ResultCodeEnum;
import com.chen.web_chat.entity.vo.LoginVo;
import com.chen.web_chat.entity.vo.Result;
import com.chen.web_chat.entity.vo.ValidateCodeVo;
import com.chen.web_chat.service.ILoginService;
import com.chen.web_chat.service.ValidateCodeService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 登录
 */
@RestController
@RequestMapping("api/user-login")
@Slf4j
public class LoginController {

    @Autowired
    ValidateCodeService validateCodeService;

    @Autowired
    private ILoginService loginService;
    @PostMapping("login")
    @ApiOperation("登录方法")
    public Result<LoginVo> login(@RequestBody LoginDto loginDTO) {
        log.info("login数据: {}", loginDTO);
        LoginVo loginVo = loginService.login(loginDTO);
        return Result.success(loginVo, ResultCodeEnum.SUCCESS);
    }


    /**
     * 获取验证码
     * @return 验证码base64
     */
    @GetMapping("getValidateCode")
    @ApiOperation("获取验证码")
    public Result<ValidateCodeVo> generateValidateCode() {
        ValidateCodeVo validateCodeVo = validateCodeService.generateValidateCode();
        return Result.success(validateCodeVo, ResultCodeEnum.SUCCESS);
    }

}
